#define  _CRT_SECURE_NO_WARNINGS 1

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */
struct ListNode* mergeTwoLists(struct ListNode* list1, struct ListNode* list2) {
    struct ListNode* cur1, * cur2, * newnode, * head;
    cur1 = list1;
    cur2 = list2;
    newnode = head = NULL;
    if (newnode == NULL)
    {
        if (cur1->val > cur2->val)
        {
            newnode = cur2;
            head = cur2;
            cur2 = cur2->next;
        }
        else if (cur1->val < cur2->val)
        {
            newnode = cur1;
            head = cur1;
            cur1 = cur1->next;
        }
        else
        {
            newnode = cur1;
            head = cur1;
            head->next = cur2;
            head = cur2;
            cur1 = cur1->next;
            cur2 = cur2->next;
        }

    }
    while (cur1 && cur2)
    {
        if (cur1->val > cur2->val)
        {
            head->next = cur2;
            head = cur2;
            cur2 = cur2->next;
        }
        else if (cur1->val < cur2->val)
        {
            head->next = cur1;
            head = cur1;
            cur1 = cur1->next;
        }
        else
        {
            head->next = cur1;
            head = cur1;
            head->next = cur2;
            head = cur2;
            cur1 = cur1->next;
            cur2 = cur2->next;
        }
    }
    if (cur1 == NULL)
    {
        head->next = cur2;
    }
    if (cur2 == NULL)
    {
        head->next = cur1;
    }
    return newnode;
}